﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace mmq
{
    public partial class UploadFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnUpload_Click1(object sender, EventArgs e)
        {
            // when upload button is clicked, save the filename to the session 
            if (!fileTestUpload.HasFile)
                return;
            string strFileName;
            strFileName = fileTestUpload.PostedFile.FileName;
            strFileName =Page.Server.MapPath("WebSites\\ScreenShot\\"+System.IO.Path.GetFileName(strFileName));
            // We don't need the path, just the name.
            FileInfo fileinfo = new FileInfo(strFileName);
            string stemp = strFileName;
            for (int i = 0; fileinfo.Exists; i++)
            {
                strFileName = Path.GetFileNameWithoutExtension(stemp) + i.ToString() + Path.GetExtension(stemp);
                fileinfo = new FileInfo(strFileName);
            }
            strFileName = Page.Server.MapPath("WebSites\\ScreenShot\\" + strFileName);
            fileTestUpload.PostedFile.SaveAs(strFileName);
        }
    }
}
